<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<script type="text/javascript" src="${webroot}/static/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="${webroot}/static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${webroot}/static/js/bootstrap-table.js"></script>
<script type="text/javascript" src="${webroot}/static/js/app-common-2.00.0.js"></script>
<script type="text/javascript" src="${webroot}/static/js/layer/layer.js"></script>
<script src="${webroot}/static/js/jquery.form.js" type="text/javascript" ></script>
<link rel="stylesheet" type="text/css" href="${webroot}/static/js/layer/skin/layer.css"/>
<link rel="stylesheet" type="text/css" href="${webroot}/static/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${webroot}/static/css/bootstrap-table.min.css" />
<link rel="stylesheet" type="text/css" href="${webroot}/static/css/forms.css" />
<html lang="en">
<head>
    <style type="text/css">
       .order-form{
         height: 49px;
         background-color: #ccc;
       }
       .control-group{
          float: left; 
          width: 20%; 
          margin-top: 10px;
       }
       label{
         width: 96px; 
         text-align: right; 
         display: table-cell; 
         vertical-align: middle;
       }
       .control{
         display: table-cell; 
         padding-left: 3px;
       }
       .control-input{
         width: 125px;
       }
       .control-button{
         float: right; 
         padding-right: 120px; 
         padding-top: 10px;
       }
       .control-button-input{
         background-color: #009688; 
         border-color: #009688; 
         color: aliceblue; 
         width: 70px; 
         height: 28px;
         border-radius: 8px;
       }
       .control-button-input1{
         background-color: #9e9e9e1c; 
         border-color: #9e9e9e1c; 
         width: 60px; 
         height: 28px;
         border-radius: 8px;
       }
       .control-button-input2{
         background-color: #03A9F4; 
         border-color: #03A9F4; 
         color: aliceblue; 
         width: 75px; 
         height: 28px;
         border-radius: 8px;
       }
/*      tr:hover{
         background-color:#00FF00
       }  */
       thead tr{
          background-color:#9e9e9e42;
       }
       th{
         text-align: center;
         height: 35px;
       }
       td{
         height: 38px;
         text-align: center;
       }
       .layui-btn-sms {
    height: 25px;
	    line-height: 19px;
	    padding: 0 10px;
	    font-size: 12px;
	    width: 45px;
	    background-color: white;
	    color: #000000e0;
	    border: 0.5px solid #000000e0;
	}
    </style>
</head>
<body>
	<div>
	    <div style="padding-top: 25px;">
	      <input type="hidden" id="conut">
	      <input type="hidden" id="sc" name="sc" />
	      <input type="hidden" id="xg" name="xg" />
	    </div>
		<div style="position: relative;top: -11px; height: 38px;">
		    <input type="button" value="批量删除" style="display: none;" id="adbut1" class="layui-btn" onclick="delAll()" />
		    <input type="button" value="添加分类" style="display: none;" id="adbut" class="layui-btn layui-btn-normal" onclick="Add()" />
		</div>
		<form id="dictGridDiv">
		    <table id="refundId_headLeftTB" class="sui-table table-bordered"> 
		      <thead class="">
		       <tr class="colorhead">
		        <th width="100">选择</th>
		        <th width="150">序号</th>
		        <th width="260">建议类别</th>
		        <th width="180">操作</th>
		       </tr>
		      </thead> 
		      <tbody id="mainLeftDiv" class="pitch custom-js">

		      </tbody>
		    </table>
        </form>
	</div>
</body>
<script type="text/javascript">
var list = JSON.parse('${gpLists}');
for (var i = 0; i < list.length; i++) {
	if(list[i].resourceName=="添加分类"){
		$("#adbut").show();
	}
	if(list[i].resourceName=="批量删除"){
		$("#adbut1").show();
	}
	if(list[i].resourceName=="修改"){
		$("#xg").val("1");
	}
	if(list[i].resourceName=="删除"){
		$("#sc").val("1");
	}
}
	$(function(){
		select();
	});
	
	function select(){
		$.ajax({
			url : "${webroot}/feedbackclass/querypage",
			type : "POST",
			dataType : "json",
			async : false,
			cache : false,
			success : function(obj) {
				var str = "";
				if(obj.rows != null){
					for (var i = 0; i < obj.rows.length; i++) {
						str += "<tr><td> <input type='checkbox' id='"+obj.rows[i].id+"' style='width: 25px; height: 20px;'></td>";
						str += "<td>"+ parseInt(i+1) +"</td>";
						str += "<td>"+ obj.rows[i].suggestName +"</td>";
						str +="<td>";
						if($("#xg").val() == '1'){
							str +="<input type='button' value='修改' class='layui-btn layui-btn-primary layui-btn-sms' onclick='dateil(\""+ obj.rows[i].id+ "\")' /> &nbsp;&nbsp;";
						}
						if($("#sc").val() == '1'){
							str +="<input type='button' value='删除' class='layui-btn layui-btn-primary layui-btn-sms' onclick='rmFeed(\""+ obj.rows[i].id+ "\")' />";
						}
						str += "</td></tr>";
					}
			        $("#mainLeftDiv").append(str);
			        $("#conut").val(obj.rows.length);
				}
			}
		})
	}
	
	//批量删除
	function delAll(){
		var ss= "";
		$.each($('input:checkbox'),function(){
	        if(this.checked){
	           ss += $(this).attr("id")+",";
	        }
	    });
		layer.confirm('确定要删除吗?', function() {
		  $.ajax({
			url : "${webroot}/feedbackclass/delete",
			type : "POST",
			dataType : "json",
			async : false,
			data:{
			   'id' : ss
			},
			cache : false,
			success : function(obj) {
				if (obj != null) {
					layer.msg("操作成功");
					$("#mainLeftDiv").empty();
					setTimeout(select(),1000);
				}else{
					layer.msg("操作失败");
				}		
			}
		  })
	    })
	}
	
	//添加分类
	function Add(){
	 var i= parseInt($("#conut").val())+1;
	 $("#conut").val(i);
	 var str = "<tr id='atr"+ i +"'><td><input type='checkbox' style='width: 25px; height: 20px;'></td>";
		str += "<td>"+ i +"</td>";
		str += "<td> <input type='text' id='suggestName"+i+"' style=''></td>";
		str += "<td><input type='button' class='layui-btn layui-btn-sm layui-btn-normal' onclick='save(suggestName"+ i +");' value='确认'/>&nbsp;&nbsp;<input type='button' class='layui-btn layui-btn-sm layui-btn-danger' onclick='cole(atr"+ i +");' value='取消' /></td></tr>";
		$("#mainLeftDiv").append(str);
	}
	
	//取消
	function cole(id){
		id.remove();
		var i= parseInt($("#conut").val())-1;
		$("#conut").val(i);
	}
	
	//确认
	function save(name){
		var suggestName = $("#"+name.id).val();
		$.ajax({
			url : "${webroot}/feedbackclass/insert",
			type : "POST",
			dataType : "json",
			async : false,
			data:{
			   'suggestName' : suggestName
			},
			cache : false,
			success : function(obj) {
				if (obj != null) {
					$("#mainLeftDiv").empty();
					setTimeout(select(),1000);
				}else{
					layer.msg("操作失败");
				}		
			}
		})
	}
	
	//删除
	function rmFeed(id){
	  layer.confirm('确定要删除吗?', function() {
		$.ajax({
			url : "${webroot}/feedbackclass/delete",
			type : "POST",
			dataType : "json",
			async : false,
			data:{
			   'id' : id
			},
			cache : false,
			success : function(obj) {
				if (obj != null) {
					layer.msg("操作成功");
					setTimeout('window.location.reload()',3000);
				}else{
					layer.msg("操作失败");
				}		
			}
		})
	  })
	}
	
	//修改分类
	function dateil(id) {
		var layerIndex = layer.open({
			type : 2,
			shade : [0.3,'#000'],
			fix : false,
			title : '修改',
			maxmin : true,
			Method : "POST",
			content : '${webroot}/feedbackclass/detail?id='+id,
			area : [ '340px', '210px' ],
			end : function(index) {
				//刷新页面
				$("#dictGridDiv").bootstrapTable('destroy');
				var oTable = new TableInit();
				oTable.Init();
			}
		});
	}
</script>
</html>